package com.bwie.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bwie.pojo.*;
import com.bwie.service.TbBrandService;
import com.bwie.service.TbOrderService;
import com.bwie.service.TbProdAttaService;
import com.bwie.service.TbProdService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import com.bwie.vo.ProdInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/prod/index")
public class IndexController {

    @Autowired
    TbProdService prodService;

    @Autowired
    TbProdAttaService prodAttaService;

    @Autowired
    private TbBrandService brandService;

    @Autowired
    TbOrderService orderService;

    @ApiOperation("商品分页")
    @PostMapping("/prodPageList")
    public R prodPageList(@RequestBody PageInfoVo pageInfoVo){
        return prodService.pageList(pageInfoVo);
    }


    @ApiOperation("品牌分页")
    @PostMapping("/BrandList")
    public R brandList(@RequestBody PageInfoVo pageInfoVo){
        return brandService.BradList(pageInfoVo);
    }

    @ApiOperation("添加品牌")
    @PostMapping("toAdd")
    public R toAdd(@RequestBody TbBrand tbBrand){
        return brandService.tbAdd(tbBrand);
    }

    @ApiOperation("修改状态")
    @PostMapping("/updateStatus/{brandId}")
    public R updateStatus(@PathVariable(name = "brandId")Integer brandId){
        return brandService.updateStatus(brandId);
    }

    @ApiOperation("批量删除")
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<TbProd> ids ){
        return prodService.deleteBatch(ids);
    }

    @ApiOperation("商品分类树形表单")
    @PostMapping("/prodTreeList")
    public R prodTreeList(@RequestBody PageInfoVo pageInfoVo){
        return prodService.prodTreeList(pageInfoVo);
    }

    @ApiOperation("商品分类添加")
    @PostMapping("/classfitySave")
    public R classfitySave(@RequestBody TbType tbType){
        return prodService.classfitySave(tbType);
    }


    @ApiOperation("添加商品")
    @PostMapping("/saveProd")
    public R saveProd(@RequestBody TbProd tbProd){
        return prodService.saveProd(tbProd);
    }


    @ApiOperation("商品品牌")
    @PostMapping("/getBrandList")
    public R getBrandList(){
        return brandService.getBrandList();
    }

    @ApiOperation("添加商品附件")
    @PostMapping("/saveAtta")
    public R saveAtta(@RequestBody TbProdAtta tbProdAtta){
        return prodAttaService.saveAtta(tbProdAtta);
    }

    @ApiOperation("订单分页")
    @PostMapping("/getOrderList")
    public R getOrderList(@RequestBody PageInfoVo pageInfoVo){
        return orderService.getOrderList(pageInfoVo);
    }

    @ApiOperation("订单批量删除")
    @PostMapping("/deleteOrder")
    public R deleteOrder(@RequestBody List<TbOrder> orderList){
        return orderService.deleteOrder(orderList);
    }

    @ApiOperation("导出")
    @GetMapping("/exportAll/{ids}")
    public void expoprtAll(@PathVariable("ids")String ids){
         orderService.export(ids);
    }

    @ApiOperation("添加订单")
    @PostMapping("/addOrder")
    public R addOrder(@RequestBody List<TbProdInfo> prodInfoList){
        return orderService.addOrder(prodInfoList);
    }

    @ApiOperation("商品明细分页")
     @PostMapping("/prodInfoList")
    public R prodInfoList(@RequestBody ProdInfoVo prodInfoVo){


       return orderService.selectPageInfo(prodInfoVo);
   }

   @ApiOperation("根据商品id查找详情")
    @PostMapping("/getProdInfo/{prodId}")
    public R getProdInfo(@PathVariable("prodId")Integer prodId){
        return prodService.getProdInfo(prodId);
   }


   @ApiOperation("添加商品详情")
    @PostMapping("/saveProdInfo")
    public R saveProdInfo(@RequestBody TbProdInfo tbProdInfo){
        return prodService.saveProdInfo(tbProdInfo);
   }


    @ApiOperation("测试")
    @PostMapping("/getTest")
    public R getTest(){
        return null;
   }
}
